using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using DNAide.Drawing;
using DNAide.Web.UI.Controls;

namespace DNAide.Website.UserControls
{
	public partial class ImageManipulation : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			PlaceHolder plh = (PlaceHolder)this.FindControl(string.Format("{0}Plh", SiteMap.CurrentNode.Key));
			if (plh != null)
			{
				plh.Visible = true;
			}
		}

		protected override void OnInit(EventArgs e)
		{
			switch (SiteMap.CurrentNode.Key)
			{
				case "ImageManipulationCombiningEffects":
					this.ImageTransform11.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform11_ApplyTransformations);
					break;
				case "ImageManipulationDrawingOnToCanvas":
					this.ImageCanvas1.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageCanvas1_ApplyTransformations);
					this.ImageCanvas2.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageCanvas2_ApplyTransformations);
					break;
				case "ImageManipulationText":
					this.ImageText7.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageText7_ApplyTransformations);
					break;
				case "ImageManipulationCropping":
					this.ImageCrop1.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageCrop1_ApplyTransformations);
					break;
				case "ImageManipulationRotating":
					this.ImageRotate1.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageRotate1_ApplyTransformations);
					break;
				case "ImageManipulationFilters":
					this.ImageTransform1.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform1_ApplyTransformations);
					this.ImageTransform2.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform2_ApplyTransformations);
					this.ImageTransform3.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform3_ApplyTransformations);
					this.ImageTransform4.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform4_ApplyTransformations);
					this.ImageTransform5.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform5_ApplyTransformations);
					this.ImageTransform6.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform6_ApplyTransformations);
					this.ImageTransform7.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform7_ApplyTransformations);
					this.ImageTransform8.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform8_ApplyTransformations);
					this.ImageTransform9.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform9_ApplyTransformations);
					this.ImageTransform10.ApplyTransformations += new DNAideImageControl.ApplyTransformationsEventHandler(ImageTransform10_ApplyTransformations);
					break;
			}
			base.OnInit(e);
		}

		void ImageTransform11_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.GrayScale(bitmapToTransform);
			BitmapAide.Water(bitmapToTransform, 10, true);
			bitmapToTransform.RotateFlip(RotateFlipType.Rotate90FlipNone);
		}

		void ImageCanvas2_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			Bitmap watermark = BitmapAide.Load(Server.MapPath("~/Client/Images/WaterMark.png"));
			BitmapAide.DrawOnToCanvasBitmap(ref bitmapToTransform, watermark, DrawPosition.BottomRight);
			watermark.Dispose();
		}

		void ImageCanvas1_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			Bitmap picture = BitmapAide.Load(Server.MapPath("~/Client/Images/FramePicture.jpg"));
			BitmapAide.DrawOnToCanvasBitmap(ref bitmapToTransform, picture, DrawPosition.CenterCenter);
			picture.Dispose();
		}

		void ImageText7_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Pixellate(bitmapToTransform, 3, true);
		}

		void ImageCrop1_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Crop(ref bitmapToTransform, 131, 91, 50, 50);
		}

		void ImageRotate1_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			bitmapToTransform.RotateFlip(RotateFlipType.Rotate90FlipNone);
		}

		void ImageTransform1_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.GrayScale(bitmapToTransform);
		}

		void ImageTransform2_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Brightness(bitmapToTransform, 100);
		}

		void ImageTransform3_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Contrast(bitmapToTransform, 100);
		}

		void ImageTransform4_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Sharpen(bitmapToTransform, 11);
		}

		void ImageTransform5_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Smooth(bitmapToTransform, 11);
		}

		void ImageTransform6_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.GaussianBlur(bitmapToTransform, 4);
		}

		void ImageTransform7_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.EmbossLaplacian(bitmapToTransform);
		}

		void ImageTransform8_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Pixellate(bitmapToTransform, 10, true);
		}

		void ImageTransform9_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Invert(bitmapToTransform);
		}

		void ImageTransform10_ApplyTransformations(object sender, ref Bitmap bitmapToTransform)
		{
			BitmapAide.Water(bitmapToTransform, 10, true);
		}
	}
}